package com.frank.code_notes.C01_array;

import cn.hutool.core.lang.Console;

/**
 * @Description 283.移动零
 * @Author zhoujr
 * @Data 2024/11/25 15:46
 */
public class L283MoveZero {

    /**
     * @Description 关键在于慢指针的移动时机
     */
    public static void moveZeroes(int[] nums) {
        int slow = 0;
        for (int fast = 0; fast < nums.length; fast++) {
            if (nums[fast] != 0) { // != 0 慢指针移动
                int temp = nums[slow];
                nums[slow++] = nums[fast];
                nums[fast] = temp;
            }
        }
        Console.log(nums);
    }


    public static void main(String[] args) {
        moveZeroes(new int[]{1, 0, 1, 3, 0, 3, 12});
        moveZeroes(new int[]{0});
    }

}
